from __future__ import absolute_import
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from Qshop.celery import app


@app.task
def add():
    x, y = 1,2
    print(x+y)
    return x+y

@app.task
def sendMial(content,email):
    from Qshop.settings import MAIL_SENDER,MAIL_PASSWORD,MAIL_SERVER,MAIL_PORT
    content = """
        如果确认是本人修改密码，请点击下放链接进行密码修改
        <a href="%s">点击链接确认</a>
    """%content
    print(content)
    # 构建邮件格式
    message = MIMEText(content, "html", "utf-8")
    message["To"] = Header(email,'utf-8')
    message["From"] = Header(MAIL_SENDER,'utf-8')
    message["Subject"] = Header("密码修改",'utf-8')

    # 发送邮件
    smtp = smtplib.SMTP_SSL(MAIL_SERVER, MAIL_PORT)
    smtp.login(MAIL_SENDER, MAIL_PASSWORD)
    smtp.sendmail(MAIL_SENDER, [email], message.as_string())
    smtp.close()
    return "邮件已经发送"